<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
request.setAttribute("orgType",request.getParameter("organization.orgType"));
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
		<title>修改部门</title>
	<link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
	<script language="javascript" src="<%=path %>/js/syAjax.js"></script>
	<script type="text/javascript">
	var objectHIDDENID;
	var orgId;
		function doUpdate()
		{
			var name=document.getElementById("orgName");
			var sort=document.getElementById("sort");
			//2010-10-12  添加设置部门负责人
	         var paramArr="";
	         
	         var userId =document.getElementsByName("UserId");
			 if(userId!=null && userId.length>0){
				for(var i=0;i<userId.length;i++){
					paramArr+=userId[i].value+",";
				}
			 }
	         
	        if(name.value=="")
	        {
	          alert("名称不能为空！");
	          name.focus();
	          return;
	        }
	        if(!/^-?[\d]{0,9}$/.test(sort.value))
        	{
          	 alert("显示序号应为数字！");
         	 sort.value="";
          	 sort.focus();
         	 return;
        	}
	        
	        syAjax.request("post","<%=path %>/updateorganizationAction.action","organization.name="+name.value+"&organization.sort="+sort.value+"&organization.organizationId="+document.getElementById("orgId").value+"&userIds="+paramArr+"&years=${applicationScope.currentYear }&role.roleId=bmfzr&organization.orgType=2",{success:initSuccessResult,fail:onFail,type:'plain'});
      }
      
      function initSuccessResult(data){
		parent.refreshJsp();
	  }
	  function doChooseUser(returnStr){
	//原版内容
		var idStr;
		if(returnStr==undefined){
			return;
		}
		if(returnStr!=null && returnStr!=""){
			var UserArr = returnStr.substring(0,returnStr.length-1).split(",");
			var UserNameStr="";
				for(var i=0;i<UserArr.length;i++){
					var user=UserArr[i];
					var sonArr=user.split("_");
					if((i+1)%5==0){
						UserNameStr+="&nbsp;&nbsp;"+sonArr[1]+"&nbsp;&nbsp;&nbsp;"+"<input name=\"UserId\" type=\"hidden\" value=\""+sonArr[0]+"\"/><br>";
					}else{
						UserNameStr+="&nbsp;&nbsp;"+sonArr[1]+"&nbsp;&nbsp;&nbsp;"+"<input name=\"UserId\" type=\"hidden\" value=\""+sonArr[0]+"\"/>";
					}
					idStr+=sonArr[0]+",";
				}
				document.getElementById("UserIds").value=idStr;
				if(UserNameStr!=""){									
					document.getElementById("pName").innerHTML=UserNameStr;					
				}	
		}else{
			document.getElementById("pName").innerHTML="点击此处设置部门负责人";
		}
	  }
	function giveParamArr(){
		return document.getElementById(objectHIDDENID).value;
	}
	  function choseUser(){
	  	objectHIDDENID="UserIds";
		  if('${applicationScope.currentYear}'==null || '${applicationScope.currentYear}'==""){
			alert("未设置当前年度，请通知管理员进行设置！");
			return;
		   }
	       var url="<%=path%>/toSelectTeacherorganizationAction.action?years=${applicationScope.currentYear}&role.roleId=bmfzr&actionURL=&t="+new Date();	
		   parent.displayModuleDiv(url);
    }
	</script>
  </head>
  
  <body bgcolor="#ECE9D8">
   <form action="<%=path %>/updateorganizationAction.action" method="post">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="41%" bgcolor="#ECE9D8">&nbsp;</td>
    <td width="59%" align="left" bgcolor="#ECE9D8">&nbsp;</td>
  </tr>
  <tr>
    <td height="30" align="right" bgcolor="#ECE9D8" class="f_6">部门编号：</td>
    <td align="left" bgcolor="#ECE9D8" class="f_6">${organization.organizationId }</td>
  </tr>
  <tr>
    <td height="30" align="right" bgcolor="#ECE9D8" class="f_6">部门名称：</td>
    <td align="left" bgcolor="#ECE9D8" class="f_6"><input type="text" name="organization.name" id="orgName" value="${organization.name }" maxlength="25"/></td>
    
  </tr>
  
  
  <tr>
     <td height="30" align="right" bgcolor="#ECE9D8" class="f_6">部门负责人：</td>
     <td align="left">
     <input type="hidden" name="years" value="${applicationScope.currentYear }"/>
     <input type="hidden" name="role.roleId" value="bmfzr"/>
     <c:set value="" var="totalArr"></c:set>
     <div style="border:1px;border-style:dotted; background-color: #FFFFFF;width: 150px" onclick="choseUser();" class="border_3"onmouseover="this.style.backgroundColor='#e4f5ff'" onmouseout="this.style.backgroundColor=''" style="cursor:pointer;" id="pName">
     <c:choose>
     <c:when test="${! empty requestScope.UserList}">
     <c:forEach items="${requestScope.UserList}" var="user" varStatus="i" begin="0" step="1">    
     <c:set value="${user.userId},${totalArr}" var="totalArr"></c:set>         
	 <c:if test="${i.count%5==0}">
		 &nbsp;&nbsp;${user.name }&nbsp;&nbsp;<input name="UserId" type="hidden" value="${user.userId }"/><br>
	 </c:if>
	 <c:if test="${i.count%5!=0}">
		 &nbsp;&nbsp;${user.name }&nbsp;&nbsp;<input name="UserId" type="hidden" value="${user.userId }"/>
	 </c:if>  
	 </c:forEach>
     </c:when>
     <c:otherwise>
      点击此处设置部门负责人
     </c:otherwise>
     </c:choose>
     </div>
     <input type="hidden"  value="${totalArr}" id="UserIds" />
     </td>
  </tr>
  
  
  <tr>
    <td height="30" align="right" bgcolor="#ECE9D8"><span class="f_6">显示序号：</span></td>
    <td align="left" bgcolor="#ECE9D8" class="f_6">
    	<input type="text" name="organization.sort" value="${organization.sort }" id="sort" />
    	<input type="hidden" name="organization.organizationId" value="${organization.organizationId }" id="orgId" />
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#ECE9D8">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td bgcolor="#ECE9D8">&nbsp;</td>
    <td height="40" align="left" bgcolor="#ECE9D8"><label>
      <input type="button" onclick="doUpdate();" name="Submit" value="提 交" />
    </label></td>
  </tr>
</table>
</form>
  </body>
</html>
